Skip to content

Fix flaky 'broadcasts realm events' tests by waiting for both index events#4884

Merged
habdelra merged 2 commits into
mainfrom
worktree-fix-flaky-broadcasts-realm-events
May 19, 2026
Merged

Fix flaky 'broadcasts realm events' tests by waiting for both index events#4884
habdelra merged 2 commits into
mainfrom
worktree-fix-flaky-broadcasts-realm-events

Conversation

@habdelra
Copy link
Copy Markdown
Contributor

Summary

  • The broadcasts realm events tests in card-source-endpoints-test.ts and realm-endpoints-test.ts intermittently fail with Incremental index initiation event not found (seen in run 26105757476).
  • Root cause: the initiation and completion realm events are broadcast without await ordering, so matrix sync can surface them in either order. The wait helper polled only for the completion event, then the caller re-fetched and asserted on both — racing on the initiation event still being in flight.
  • Fix: wait until both incremental-index-initiation and incremental events are visible before returning. Same fix applied in both copies of the helper.
  • Diagnostic logging added in case the fix doesn't fully land: the throw path now logs the realm events actually seen, and the wait timeout message reports which of the two events were observed at timeout.

Test plan

  • Re-run the Realm Server Tests shard 4 in CI; card source DELETE request > public writable realm > broadcasts realm events and the sibling cases should pass consistently.
  • If a future flake recurs, the realm-server log will include a [expectIncrementalIndexEvent] missing event(s) … line (or the timeout message variant) listing what was visible, so we can distinguish a real missing-event bug from sync ordering.

🤖 Generated with Claude Code

The `broadcasts realm events` tests race on matrix sync ordering: the
initiation and completion realm events are emitted without await
ordering, so the completion event can become visible before the
initiation event. The previous wait helper polled only for completion,
then asserted on both events — when the initiation event hadn't synced
yet, the assertion threw "Incremental index initiation event not found".

Wait until BOTH events are visible before returning, and dump the realm
events actually seen if either is still missing, so a future regression
leaves a usable breadcrumb instead of a bare error.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses intermittent failures in the realm-server test suite where incremental indexing realm events can arrive out-of-order via Matrix sync. It updates the “wait for incremental index event” helpers to only return once both the initiation (incremental-index-initiation) and completion (incremental) events are visible, and improves diagnostics when expectations fail.

Changes:

  • Update incremental-index event waiting logic to require both initiation + completion events before proceeding.
  • Add more informative error/timeout diagnostics showing what was observed when expected events are missing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/realm-server/tests/realm-endpoints-test.ts Updates the local wait helper to require both initiation and completion index events; enhances failure logging.
packages/realm-server/tests/helpers/indexing.ts Updates the shared wait helper to require both events and adds a detailed timeout message + improved failure diagnostics in assertions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/realm-server/tests/realm-endpoints-test.ts Outdated
realm-endpoints-test.ts duplicated the helper with a 1s waitUntil
default, which would re-introduce flakiness now that the wait requires
two events. Import the shared helper (5s timeout + timeoutMessage)
instead.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

Host Test Results

    1 files      1 suites   3h 0m 50s ⏱️
2 673 tests 2 658 ✅ 15 💤 0 ❌
5 384 runs  5 354 ✅ 30 💤 0 ❌

Results for commit 044a093.

Realm Server Test Results

    1 files  ±  0      1 suites  ±0   9m 8s ⏱️ + 1m 44s
1 414 tests +268  1 414 ✅ +268  0 💤 ±0  0 ❌ ±0 
1 501 runs  +283  1 501 ✅ +283  0 💤 ±0  0 ❌ ±0 

Results for commit 044a093. ± Comparison against earlier commit d91d013.

@habdelra habdelra requested a review from a team May 19, 2026 16:11
@habdelra habdelra merged commit 8b087f2 into main May 19, 2026
94 of 95 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants